<?php
class shop_log extends CI_Controller {
	function index() {
		$this -> pub -> logp('浏览操作日志', '2');
		$da = $this -> pub -> get_setting('操作日志', 'Operation Logs');
		$this -> load -> view('adminx/shop_log', $da);
	}

	function get() {
		$this -> pub -> logp('获取操作日志', '2');
		$day1 = strtotime($this -> input -> post('day1'));
		$day2 = strtotime($this -> input -> post('day2')) + 86400;

		$this -> db -> where('log_mktime >', $day1);
		$this -> db -> where('log_mktime <', $day2);
		
		if ($this -> input -> post('key') or $this -> input -> post('name')) {
			$this -> db -> select('count(*)');

			if ($this -> input -> post('key')) {
				$this -> db -> like('nr', $this -> input -> post('key'));
			}
			if ($this -> input -> post('name')) {
				$this -> db -> like('name', $this -> input -> post('name'));
			}

			$q = $this -> db -> get_where('log');
			$ls = $q -> row_array(0);
			$num = $ls['count(*)'];

			if ($this -> input -> post('key')) {
				$this -> db -> like('nr', $this -> input -> post('key'));
			}
			if ($this -> input -> post('name')) {
				$this -> db -> like('name', $this -> input -> post('name'));
			}

		} else {
			$this -> db -> select('count(*)');
			$q = $this -> db -> get_where('log');
			$ls = $q -> row_array(0);
			$num = $ls['count(*)'];
		}
		//一共的页数
		$da['num'] = ceil($num / 30);

		$page = is_numeric($this -> input -> post('page')) && $this -> input -> post('page') > 0 ? $this -> input -> post('page') : 1;
		$page = $page > $da['num'] ? $da['num'] : $page;
		$da['page'] = $page;

		$page = ($page - 1) == -1 ? 0 : ($page - 1);

		$this -> db -> limit(30, $page * 30);

		$this -> db -> order_by('log_id', 'desc');
		$this -> db -> where('log_mktime >', $day1);
		$this -> db -> where('log_mktime <', $day2);
		$q = $this -> db -> get_where('log');
		$da['content'] = '';
		foreach ($q->result_array() as $v) {
			$da['content'] .= '<tr>';
			if ($v['mid']) {
				$this -> db -> select('nickname,mid,headimgurl');
				$qq = $this -> db -> get_where('member', array('mid' => $v['mid']));
				$m = $qq -> row_array(0);
				$da['content'] .= '<td><a target="_blank" href="/iadmin/member/info/' . $m['mid'] . '"><img width="48" src="' . ($m['headimgurl'] ? $m['headimgurl'] : '/mex/lance/img/tx.jpg') . '" /></a></td>';
				if ($v['xid']) {
					$this -> db -> select('name');
					$qq = $this -> db -> get_where('staff', array('staff_id' => $v['xid']));
					$s = $qq -> row_array(0);
					$da['content'] .= '<td>' . ($m['nickname'] ? $m['nickname'] : '游客') . '<br>' . $s['name'] . '</td>';
				} else {
					$da['content'] .= '<td>' . ($m['nickname'] ? $m['nickname'] : '游客') . '</td>';
				}
			} else {
				$da['content'] .= '<td><img width="48" src="/mex/lance/img/tx.jpg" /></td>';
				$da['content'] .= '<td>游客</td>';
			}
			$da['content'] .= '<td>' . $v['nr'] . '</td>';
			$da['content'] .= '<td>' . $v['browser'] . '</td>';
			$da['content'] .= '<td>' . $v['platform'] . '</td>';
			$da['content'] .= '<td>' . date('Y-m-d H:i:s', $v['log_mktime']) . '</td>';
			$da['content'] .= '<td>' . $v['log_mkip'] . '</td>';
			$da['content'] .= '</tr>';
		}
		$da['type'] = 1;
		echo json_encode($da);
	}

}
?>